package com.study.demo.aop.demo1_2.interceptor;

import com.study.demo.aop.demo1_2.operation.LogOperationSource;
import com.study.demo.aop.demo1_2.pointcut.LogOperationSourcePointcut;
import org.springframework.aop.ClassFilter;
import org.springframework.aop.Pointcut;
import org.springframework.aop.support.AbstractBeanFactoryPointcutAdvisor;

/**
 * @author: elvin
 * @time: 2019-10-16 14:29
 * @desc:
 **/
public class BeanFactoryLogOperationSourceAdvisor  extends AbstractBeanFactoryPointcutAdvisor {

    private LogOperationSource logOperationSource;

    private final LogOperationSourcePointcut pointcut = new LogOperationSourcePointcut() {
        //通过这个方法, 将 logOperationSource 传入 LogOperationSourcePointcut 类
        @Override
        protected LogOperationSource getLogOperationSource() {
            return logOperationSource;
        }
    };

    public BeanFactoryLogOperationSourceAdvisor() {
    }

    public BeanFactoryLogOperationSourceAdvisor(LogOperationSource logOperationSource) {
        this.logOperationSource = logOperationSource;
    }

    @Override
    public Pointcut getPointcut() {
        return pointcut;
    }

    public void setLogOperationSource(LogOperationSource logOperationSource) {
        this.logOperationSource = logOperationSource;
    }

    public void setClassFilter(ClassFilter classFilter){
        this.pointcut.setClassFilter(classFilter);
    }
}
